<form action="{:U('Common/addCommon')}" method="post" class="form-horizontal">
    <div class="form-item">
        <label class="item-label">商品名</label>
        <div class="controls">
            <input type="text" class="text input-large" name="name" value="{$data.name|default=''}">
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">商品分类</label>
        <div class="controls">
        <select name="class_id">
            <option value="0" selected="">--请选择--</option>
            <volist name="_class" id="v">
                <option value="{$v.id}" <if condition="$v['id'] eq $data['class_id']">selected="selected"</if>>{$v.name}</option>          
                <volist name="v['_child']" id="v2">
                    <option value="{$v2.id}" <if condition="$v2['id'] eq $data['class_id']">selected="selected"</if>>&nbsp;&nbsp;├{$v2.name}</option>
                </volist>
            </volist>
        </select>               
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">商品品牌</label>
        <div class="controls">
        <select name="brand_id">
            <volist name="_brand" id="v">
                <option value="{$v.id}" <if condition="$v['id'] eq $data['brand_id']">selected="selected"</if>>{$v.name}</option>          
            </volist>
        </select>               
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">单位</label>
        <div class="controls">
        <select name="unit_id">
            <volist name="units" id="v">
                <option value="{$v.id}" <if condition="$v['id'] eq $data['unit_id']">selected="selected"</if>>{$v.name}</option>          
            </volist>
        </select>               
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">是否限购</label>
        <div class="controls">
            <label class="radio">
                <input type="radio" value="0" name="is_ppl" class="is_ppl" <if condition="$data['is_ppl'] eq 0">checked="checked"</if>>非限购                                  
            </label>
            <label class="radio">
                <input type="radio" value="1" name="is_ppl" class="is_ppl" <if condition="$data['is_ppl'] eq 1">checked="checked"</if>>限购
            </label>         
        </div>
    </div>
    <div class="form-item ppl" style="<eq name='data.is_ppl' value='0'>display:none;</eq>">
        <label class="item-label">库存</label>
        <div class="controls">
            <input type="text" class="text input-large" name="ppl_num" value="{$data.ppl_num|default='0'}">
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">点粉价</label>
        <div class="controls">
            <input type="text" class="text input-large" name="price" value="{$data.price|default='0.00'}">
        </div>
    </div>
	<div class="form-item">
        <label class="item-label">店面价</label>
        <div class="controls">
            <input type="text" class="text input-large" name="shop_price" value="{$data.shop_price|default='0.00'}">
        </div>
    </div>
    <if condition="$data['user_type'] eq 0">
        <div class="form-item">
            <label class="item-label">进价</label>
            <div class="controls">
                <input type="text" class="text input-large" name="jj_price" value="{$data.jj_price|default='0.00'}">
            </div>
        </div>
    </if>
	<div class="form-item">
        <label class="item-label">折扣</label>
        <div class="controls">
            <input type="text" class="text input-large" name="zhekou" value="{$data.zhekou|default=''}" style="width:30px;text-align:center;">%
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">销量</label>
        <div class="controls">
            <input type="text" class="text input-large" name="sale_count" value="{$data.sale_count|default=0}">
        </div>
    </div>
    <div class="controls">
        <label class="item-label">图片</label>
        <input type="file" id="upload_picture">
        <input type="hidden" name="picture" id="picture" value="{$data.picture|default=''}"/>
        <div class="upload-img-box">
        <notempty name="data['picture']">
            <div class="upload-pre-item"><img src="{$data.picture|get_cover='path'}"/></div>
        </notempty>
        </div>
    </div>
    <script type="text/javascript">
    //上传图片
    /* 初始化上传插件 */
    $("#upload_picture").uploadify({
        "height"          : 30,
        "swf"             : "__STATIC__/uploadify/uploadify.swf",
        "fileObjName"     : "download",
        "buttonText"      : "上传图片",
        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
        "width"           : 120,
        'removeTimeout'   : 1,
        'fileTypeExts'    : '*.jpg; *.png; *.gif;',
        "onUploadSuccess" : uploadPicture,
        'onFallback' : function() {
            alert('未检测到兼容版本的Flash.');
        }
    });
    function uploadPicture(file, data){
        var data = $.parseJSON(data);
        var src = '';
        if(data.status){
            $("#picture").val(data.id);
            src = data.url || '__ROOT__' + data.path;
            $("#picture").parent().find('.upload-img-box').html(
                '<div class="upload-pre-item"><img src="' + src + '"/></div>'
            );
        } else {
            updateAlert(data.info);
            setTimeout(function(){
                $('#top-alert').find('button').click();
                $(that).removeClass('disabled').prop('disabled',false);
            },1500);
        }
    }
    </script>
    <div class="form-item">
        <label class="item-label">是否上架/下架</label>
        <div class="controls">
            <label class="radio">
                <input type="radio" value="0" name="is_sj" <if condition="$data['is_sj'] eq 0">checked="checked"</if>>下架                                    
            </label>
            <label class="radio">
                <input type="radio" value="1" name="is_sj" <if condition="$data['is_sj'] eq 1">checked="checked"</if>>上架
            </label>
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">是否推荐</label>
        <div class="controls">
            <label class="radio">
                <input type="radio" value="0" name="is_recommend" <if condition="$data['is_recommend'] eq 0">checked="checked"</if>>否                                    
            </label>
            <label class="radio">
                <input type="radio" value="1" name="is_recommend" <if condition="$data['is_recommend'] eq 1">checked="checked"</if>>是
            </label>
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">是否热销</label>
        <div class="controls">
            <label class="radio">
                <input type="radio" value="0" name="is_hot" <if condition="$data['is_hot'] eq 0">checked="checked"</if>>否                              
            </label>
            <label class="radio">
                <input type="radio" value="1" name="is_hot" <if condition="$data['is_hot'] eq 1">checked="checked"</if>>是
            </label>
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">内容</label>
        <div class="controls">
            <label class="textarea">
                <textarea name="content">{$data.content}</textarea>
                {:hook('adminArticleEdit', array('name'=>'content','value'=>$data['content']))}
            </label>
        </div>
    </div>
    <div class="form-item">
        <input type="hidden" name="table" value="goods">
        <input type="hidden" name="methods" value="Goods">
        <if condition="$data['user_type'] eq 0">
        <input type="hidden" name="fields" value="class_id,text;brand_id,text;name,text;price,text;picture,text;sale_count,text;is_sj,text;is_recommend,text;is_hot,text;content,text;ctime,date;zhekou,text;shop_price,text;jj_price,text;unit_id,text;utime,text-date;is_ppl,text;ppl_num,text">
        <else />
            <input type="hidden" name="fields" value="class_id,text;brand_id,text;name,text;price,text;picture,text;sale_count,text;is_sj,text;is_recommend,text;is_hot,text;content,text;ctime,date;zhekou,text;shop_price,text;utime,text-date;is_ppl,text;ppl_num,text">
        </if>
        <input type="hidden" name="id" value="{$data.id|default=0}">
        <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
        <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
    </div>
</form>
<script type="text/javascript">
    $(function(){
        $('.is_ppl').click(function(){
            if( Number($('input:radio[name="is_ppl"]:checked').val()) == 1 ){
                $('.ppl').show();
                $('.idnum').show();
            }else{
                $('.ppl').hide();
                $('.idnum').hide();
            }
        });
    });
</script>
